<?php

	class LoginView {
		
		//Private variables for use in getting the login information
		private $m_getUserName = "Username";
		private $m_getPassword = "Password";
		private $m_triedToLogin = "Login";
		private $m_triedToLogOut = "Logout";
		private $m_rememberMe = "RememberMe";
		
		//Skriver ut inloggningsformuläret
		public function DoLoginBox() {
			$ret = "
		<div id='loginBox'>
			<form method='get'>
				<p>
					<label for='name'>Name: <input class='textBox' type='text' id='name' name='$this->m_getUserName' ></label>
				</p>
				<p>
					<label for='password'>Password: <input class='textBox' type='text' id='password' name='$this->m_getPassword' ></label>
				</p>
				<p id='rememberTag'>
					<input class='button' type='submit' value='Login' name='$this->m_triedToLogin' >
					<label for='rememberMe'>Remember me <input type='checkbox' id='rememberMe' name='RememberMe' ></label>
				</p>
			</form>
		</div>";
		return $ret;
		}
		
		//Skriver ut logout-knappen
		public function DoLogoutBox(){
			$ret = "
		<div id='logoutbox' >
			<a id='logout' href='?Logout=Logout' name='$this->m_triedToLogOut'>Logout</a>
		</div>";
			return $ret;
		}
		
		//Returnerar  html för meddelanden
		public function DoFeedback($message){
			return "
		<div id='feedback'>
			<p>$message</p>
		</div>";
		}
		
		//Tar hand om lösenordet
		public function GetUserName() {
			
	    	if (isset( $_GET[$this->m_getUserName]) === true) {
	      		return $_GET[$this->m_getUserName];
			} 
	    	return NULL;
  		}
		
		//Tar hand om lösenordet
		public function GetPassword() {
			
	    	if (isset( $_GET[$this->m_getPassword]) === true) {
	      		return $_GET[$this->m_getPassword];
			} 
	    	return NULL;
  		}
  		
  		//Ser om login-knappen trycks ner
  		public function TriedToLogin() {
			
	    	if (isset( $_GET[$this->m_triedToLogin]) === true) {
				return $_GET[$this->m_triedToLogin];
			}
	    	return FALSE;
  		}
  		
  		//Ser om logout-knappen trycks ner
  		public function TriedToLogOut() {
			
	    	if (isset( $_GET[$this->m_triedToLogOut]) === true) {
	      		return $_GET[$this->m_triedToLogOut];
			} 
	    	return FALSE;
  		}
  		
  		//Ser om användaren vill bli ihågkommen.
  		public function RememberUser() {
			
	    	if (isset( $_GET[$this->m_rememberMe]) === true) {
	      		return $_GET[$this->m_rememberMe];
			} 
	    	return FALSE;
  		}
		
		//Sparar användarnamnet i cookie.
  		public function SetUsernameCookie() {
  			setcookie($this->m_getUserName, $this->GetUserName(), time()+10);
  		}
		
		//Sparar lösenordet i en cookie.
  		public function SetPasswordCookie() {
			setcookie($this->m_getPassword, $this->GetPassword(), time()+10);
  		}
		
		//Hämtar UsernameCookie
  		public function GetUsernameCookie() {
  			if(isset($_COOKIE[$this->m_getUserName])){
  				return $_COOKIE[$this->m_getUserName];
			} else {
				return NULL;
			}
  		}
		
		//Hämtar PasswordCookie
  		public function GetPasswordCookie() {
  			if(isset($_COOKIE[$this->m_getPassword])){
  				return $_COOKIE[$this->m_getPassword];
			} else {
				return NULL;
			}
  		}
		
		//kollar om dågra cookies är satta
  		public function IsCoockiesSet() {
  			if(isset($_COOKIE[$this->m_getUserName]) && 
  				isset($_COOKIE[$this->m_getPassword])){
  				return TRUE;
			} else {
				return FALSE;
			}
  		}
		//kollar om dågra cookies är satta
  		public function RemoveCoockies() {
  			if(isset($_COOKIE[$this->m_getUserName]) && 
  				isset($_COOKIE[$this->m_getPassword])){
  					setcookie($this->m_getUserName, "", time()-3600);
					setcookie($this->m_getPassword, "", time()-3600);
			} 
  		}
	}
?>